package com.news.gpb.dao;

import com.news.gpb.entity.Blog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BlogDao {

    @Insert("insert into blogs(user_id,blog_title,blog_content) values(#{blog.user_id},#{blog.blog_title},#{blog.blog_content})")
    Integer addBlog(@Param("blog")Blog blog);

    @Select("select * from blogs where user_id=#{user_id} order by blog_date desc")
    List<Blog> getBlog(@Param("user_id")int user_id);

    @Select("select count(*) from blogs where user_id=#{user_id}")
    Integer countBlog(@Param("user_id") int user_id);

    @Delete("delete from blogs where blog_id=#{blog_id}")
    Integer deleteBlog(@Param("blog_id")int blog_id);


}
